import type { Router } from 'vue-router'

// 路由守卫
export default (router: Router) => {
  const whiteList = ['/login']
  const isLogin = Boolean(localStorage.getItem('token'))
  router.beforeEach((to, from, next) => {
    if (whiteList.includes(to.path)) {
      return next()
    }
    if (!isLogin) {
      return next({ path: '/login', query: { redirect: to.fullPath } })
    }
  })
}
